import { AdManager } from "../ads/AdManager";
import { BUNDLE_TYPE_ENUM, EVENT_NAME_ENUM } from "../base/EnumIndex";
import LevelPre_14 from "../game/Game_14/LevelPre_14";
import LevelPre_15 from "../game/Game_15/LevelPre_15";
import LevelPre_23 from "../game/Game_23/LevelPre_23";
import LevelPre_24 from "../game/Game_24/LevelPre_24";
import { AudioManager1 } from "../manager/AudioManager1";
import { EventManager } from "../manager/EventManager";
import { UIManager } from "../manager/UIManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ReviveUI extends cc.Component {

    onLoad() {
        AudioManager1.stopAllAudio();

        AudioManager1.playAudio("shibai", 1, BUNDLE_TYPE_ENUM.GAME)
    }

    clickBtnRevive() {
        AudioManager1.playClick();
        AdManager.showVideoAd(() => {
            UIManager.ins.close();
            let lvBase = cc.find("Canvas").getComponentInChildren(LevelPre_23);
            if (lvBase) {
                EventManager.ins.emit(EVENT_NAME_ENUM.RESUME_TIME);
                lvBase.runNodeTween(this.node, lvBase.getInterTwForName("reviveGame").interTween);
            }

            let lvBase24 = cc.find("Canvas").getComponentInChildren(LevelPre_24);
            if (lvBase24) {
                EventManager.ins.emit(EVENT_NAME_ENUM.RESUME_TIME);
                lvBase24.runNodeTween(this.node, lvBase24.getInterTwForName("reviveGame").interTween);
            }

            let lvBase15 = cc.find("Canvas").getComponentInChildren(LevelPre_15);
            if (lvBase15) {
                EventManager.ins.emit(EVENT_NAME_ENUM.RESUME_TIME);
                lvBase15.runNodeTween(this.node, lvBase15.getInterTwForName("reviveGame").interTween);
            }

            let lvBase14 = cc.find("Canvas").getComponentInChildren(LevelPre_14);
            if (lvBase14) {
                EventManager.ins.emit(EVENT_NAME_ENUM.RESUME_TIME);
                lvBase14.runNodeTween(this.node, lvBase14.getInterTwForName("reviveGame").interTween);
            }
        });
    }

    clickBtnOver() {
        AudioManager1.playClick();
        UIManager.ins.close();
        EventManager.ins.emit(EVENT_NAME_ENUM.STOP_TIME);
        UIManager.ins.showPop("OverUI", BUNDLE_TYPE_ENUM.GAME);
    }
}